<?php


/**
 * ConfigHelper - loads config
 * 
 * Example (inside controller class):
 * $this->config(); //loads config from etc/MycontrollerCtrl.ini and stores it in $this->conf
 * var_dump($this->conf)
 */
class ConfigHelper {
	public static function invoke($caller, $confName=null, $unstrict=false) {
		if(null === $confName){$confName = get_class($caller);}
		$configFile = 'etc/'.$confName.'.ini';
		if(file_exists($configFile)) {
			if(!$cfg = @parse_ini_file($configFile, true)) {
				if(!$unstrict) {
					throw new Exception ('Illegal config format in ['.$configFile.']', 500);
				}
			}			
			return $cfg;
		} else {
			if(!$unstrict) {
				throw new Exception ('Config file not found ['.$configFile.']', 500);
			}
		}
	}
}
